﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

namespace WebSite.admin.title
{
    public partial class vote_add : System.Web.UI.Page
    {
     

        // Methods
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["vid"] != null)
            {
                SQLAccess.DoSql(string.Concat(new object[] { "update DB_Vote set vote='", re.replace(this.vote.Value), "',time1='", re.replace(this.time1.Value), "',time2='", re.replace(this.time2.Value), "',isselect=", this.isselect.Checked ? "1" : "0", " where voteid=", base.Request.QueryString["vid"], "" }));
                base.Response.Write("<script language='javascript'>alert('在线调查修改成功！');window.location.href='vote.aspx';</script>");
                base.Response.End();
            }
            else
            {
                SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_Vote (vote,time1,time2,isselect) values ('", re.replace(this.vote.Value), "','", re.replace(this.time1.Value), "','", re.replace(this.time2.Value), "',", this.isselect.Checked ? "1" : "0", ")" }));
                base.Response.Write("<script language='javascript'>alert('在线调查添加成功！');window.location.href='vote.aspx';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            this.ImageButton1.Attributes["onclick"] = "return CheckFrm()";
            if (!base.IsPostBack && (base.Request.QueryString["vid"] != null))
            {
                this.upbind();
            }
        }

        private void upbind()
        {
            string sql = "select * from DB_Vote where voteid=" + base.Request.QueryString["vid"].ToString() + "";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.vote.Value = table.Rows[0]["vote"].ToString();
                this.time1.Value = table.Rows[0]["time1"].ToString();
                this.time2.Value = table.Rows[0]["time2"].ToString();
                this.isselect.Checked = (bool)table.Rows[0]["isselect"];
            }
        }

   

    }
}